layui.define('my_send', function(exports){
  var $ = layui.$
      , http_proxy = layui.http_proxy;
  // 设备分类统计
  var dataList=[];
  var dataValueList=new Array();
  $.ajax({
    type : "get",
    async : false, //异步执行
    url : http_proxy("/alarm/classificationOfEquipment"),
    dataType : "json", //返回数据形式为json
    success : function(data) {
      alarmGradingStation = data.data;
      for(var i=0;i< alarmGradingStation.length;i++){
        dataList.push( alarmGradingStation[i].system);
        var map=new Map;
        map.name= alarmGradingStation[i].system;
        map.value= alarmGradingStation[i].proportion;
        dataValueList.push(map);
      }
    },
    error : function(errorMsg) {
        alert("请求数据失败");
    }
  });
  // 网络负载
  // $.ajax({
  //   type : "get",
  //   async : false, //异步执行
  //   url : http_proxy("/top/flowList"),
  //   dataType : "json", //返回数据形式为json
  //   success : function(data) {
  //     flowList = data.data;
  //   },
  //   error : function(errorMsg) {
  //     alert("请求数据失败");
  //   }
  // });
   // 核心交换机性能
   $.ajax({
      type : "get",
      async : false, //异步执行
      url : http_proxy("/rtSwitch/getData"),
      dataType : "json", //返回数据形式为json
      success : function(data) {
        coreSwicthData = data.data;
        var list=[];
        for(var i=0;i< coreSwicthData.length;i++){
          list.push([ coreSwicthData[i].state/100]);
        }
        coreSwicthDatalist=list
      },
      error : function(errorMsg) {
          alert("请求数据失败");
      }
   });
    // 系统健康值
    $.ajax({
      type : "get",
      async : false, //异步执行
      url : http_proxy("/alarm/systemHealthValue"),
      dataType : "json", //返回数据形式为json
      success : function(data) {
        systemHealth = data.data;
      },
      error : function(errorMsg) {
          alert("请求数据失败");
      }
   });
  var list =[];
  var str;
   $.ajax({
    type : "get",
    async : false, //异步执行
    url :http_proxy('/alarm/deviceFailureStatistics'),
    dataType : "json", //返回数据形式为json
    success : function(data) {
      faultStatistics = data.data;
      for (var i = 0; i <  faultStatistics.length; i++) {
        str += '<tr>' + '<td>' + faultStatistics[i].system + '</td>' + '<td>' + faultStatistics[i].quantity + '</td>' + '</tr>';
        $('.systable tbody').html(str);
      }
    },
    error : function(errorMsg) {
        alert("请求数据失败");
    }
 });
function  roundDatas(num){
  var datas = [];
  for (var i = 0; i < num; i++) {
    datas.push({
      name: "circle" + i
    });
  }
  return datas;
};
function getDataItem() {
  var len = faultStatistics.length;
  var itemData = [];
  for (var i = 0; i < len; i++) {
    let item = {
      name: faultStatistics[i].system,
      symbolSize: faultStatistics[i].quantity,
      value: faultStatistics[i].quantity,
      itemStyle: {
        normal: {
          color: "#2D7CCB"
        }
      }
    };
    itemData.push(item);
  }
  return itemData;
};
  // 设备分类统计
  var myChart = echarts.init(document.getElementById("eventClassification"));
  option = {
    tooltip: {
      show: true,
      trigger: 'item',
      formatter: "{b}: {c} ({d}%)"
    },

    legend: {
      orient: 'horizontal',
      left: "3%",
      bottom: "3%",
      textStyle: {
        fontWeight: "normal",
        fontSize: 12,
        color: "#606266"
      },
      // data:dataList
      data:['ATS','PSD','ACS','EMCS','FAS','UPS','EMCS2','PCSADA','AFC'],
    },
    series: [
      {
        type:'pie',
        selectedMode: 'single',
        center:["50%", "40%"], //外边距 设置图左右 上下的位置
        radius:  ["40%", "50%"],
        color: ["#AF89D6", "#5ab6df", "#6a8bc0", "#4acacb", "#fe8676"],
        label: {
          normal: {
            formatter: "{b}\n{d}%",
            textStyle: {
              color: '#606266',
              fontWeight: "bold",
              fontSize: 12
            }
          }
        },
        data:[
          {value:335, name:'ATS'},
          {value:679, name:'PSD'},
          {value:1548, name:'ACS'},
          {value:335, name:'EMCS'},
          {value:679, name:'FAS'},
          {value:1548, name:'UPS'},
          {value:335, name:'EMCS2'},
          {value:679, name:'PCSADA'},
          {value:1548, name:'AFC'},
        ],
        // data:dataValueList,
        itemStyle: {
          normal: {
            label: {
              show: true,
              formatter: "{b} : {c} ({d}%)"
            },
            labelLine: { show: true }
          }
        }
      },
    ]
};
  myChart.setOption(option);

    // 网络负载
    var myChart = echarts.init(document.getElementById("netWorkData"));
      option = {
        tooltip: {
          trigger: 'axis'
      },
      color:['#00FF00','#FF0000'],
      legend: {
          data:['出口流量','入口流量'],
          icon: "rect",
          x:'right',
          textStyle:{
            color:"#606266"
          }
      },
      grid: {
          left: '6%',
          right: '4%',
          bottom: '20%',
        top:'15%',
          containLabel: true
      },
      xAxis: {
          type: 'category',
          boundaryGap: false,
          axisLabel:{
            interval:0,
            rotate:45,
            margin:2,
            textStyle:{
              color:"#606266"
            }
          },
          axisLine: {
            lineStyle: {
                color:'#606266',
                width:'1'
            }
          },
          data: ['2019-09-12','2019-09-13','2019-09-14','2019-09-15','2019-09-16','2019-09-17']
      },
      yAxis: {
          type: 'value',
          axisLabel:{
            interval:0,
            textStyle:{
              color:"#606266"
            }
          },
          axisLine: {
            lineStyle: {
                color:'#606266',
                width:'1'
            }
          },
      },
      series: [
          {
              name:'出口流量',
              type:'line',
              stack: '总量',
              data:[0.2, 0.5, 0, 0.3, 0.5, 0.1]
          },
          {
              name:'入口流量',
              type:'line',
              stack: '总量',
              data:[0.6, 0.1, 0.7, 0., 0.4, 0.5]
          },
      ]
    };
    myChart.setOption(option);

  // 核心交换机性能
  var myChart = echarts.init(document.getElementById('coreSwicthData'));
  var lableStyle = {
    normal: {
      textStyle: {
        color: '#fff',
        insideColor: '#fff',
        fontSize: 16
      }
    }
  };
  var lableStyle1 = {
    normal: {
       formatter: '{c}M',
       textStyle: {
        color: '#fff',
        insideColor: '#fff',
        fontSize: 16
      }
    }
  };
  var outlineStyle = {
    show: true,
    borderDistance: 8,
    itemStyle: {
      color: "none",
      borderColor: "#1f5888",
      borderWidth: 8
    }
  };
  var option = {
    // backgroundColor: "#0D2A42",
    title: [
      {
        text: "CPU",
        textStyle: {
          fontSize: 15,
          color: "#606266"
        },
        left: "14%",
        top: "84%",
        textAlign: "center",
        textBaseAlign: "middle"
      },
      {
        text: "内存",
        textStyle: {
          fontSize: 15,
          color: "#606266"
        },
        left: "44%",
        top: "84%",
        textAlign: "center",
        textBaseAlign: "middle"
      },
      {
        text: "内存使用率",
        textStyle: {
          fontSize: 15,
          color: "#606266"
        },
        left: "74%",
        top: "84%",
        textAlign: "center",
        textBaseAlign: "middle"
      }
    ],
    series: [
      {
        type: "liquidFill",
        data:coreSwicthDatalist[1],
        label: lableStyle,
        radius: "50%",
        shape: "rect",
        // 水球颜色
        color: ["#1f5888"],
        center: ["15%", "50%"],
        // 内图 背景色 边
        backgroundStyle: {
          color: "#0D2A42"
        },
        outline: outlineStyle
      },
      {
        type: "liquidFill",
        data: coreSwicthDatalist[0],
        label: lableStyle1,
        shape: "rect",
        radius: "50%",
        // 水球颜色
        color: ["#1f5888"],
        center: ["45%", "50%"],
        // 内图 背景色 边
        backgroundStyle: {
          color: "#0D2A42"
        },
        outline: outlineStyle
      },
      {
        type: "liquidFill",
        data: coreSwicthDatalist[2],
        label: lableStyle,
        shape: "rect",
        radius: "50%",
        // 水球颜色
        color: ["#1f5888"],
        center: ["75%", "50%"],
        // 内图 背景色 边
        backgroundStyle: {
          color: "#0D2A42"
        },
        outline: outlineStyle
      }
    ]
  };
  // 使用刚指定的配置项和数据显示图表。
  myChart.setOption(option);


  //系统健康值
var myChart = echarts.init(document.getElementById("systemHealthList"));
var labelFacade = {
  normal: {
    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
    offset: 0,
    color: "#00cefc" // 0% 处的颜色
  },
  {
    offset: 1,
    color: "#367bec" // 100% 处的颜色
  }], false)
  }
};
var lableFont = {
  normal: {
    formatter: "{d}%",
    position: "center",
    show: true,
    textStyle: {
      fontSize: "15",
      fontWeight: "normal",
      color: "#606266"
    }
  }
};
var labelFromatter = {
  normal: {
    label: {
      show: false
    },
    labelLine: {
      show: false
    }
  }
};
var titleStyle = {
  fontWeight: "normal",
  fontSize: 15,
  color: "#606266"
};
var radius = [35, 45];
option = {
  title: [
    { text:systemHealth[0].system, left: "10%", top: "65%", textStyle: titleStyle },
    { text:systemHealth[1].system, left: "46%", top: "65%", textStyle: titleStyle },
    { text:systemHealth[2].system, left: "76%", top: "65%", textStyle: titleStyle }
  ],
  color: ["rgba(176, 212, 251, 1)"],
  // backgroundColor: "#0D2A42",
  series: [
     // EMCS占比98%
    {
      type: "pie",
      center: ["15%", "40%"],
      radius: radius,
      clockWise: true, //顺逆时针
      hoverAnimation: false, //鼠标悬停跳动
      x: "0%", // for funnel
      itemStyle: labelFromatter,
      data: [
        {
          name: "EMCS",
          value: systemHealth[0].healthIndex,
          itemStyle: labelFacade,
          label: lableFont
        },
        {
          name: "residue",
          value: 100-systemHealth[0].healthIndex,
        }
      ]
    },
    //FAS占比99%
    {
      type: "pie",
      center: ["50.5%", "40%"],
      clockWise: true, //顺逆时针
      hoverAnimation: false, //鼠标悬停跳动
      radius: radius,
      x: "20%", // for funnel
      itemStyle: labelFromatter,
      data: [
        {
          name: "FAS",
          value: systemHealth[1].healthIndex,
          itemStyle: labelFacade,
          label: lableFont
        },
        { name: "residue", value: 100-systemHealth[1].healthIndex }
      ]
    },
    // 故障处理率96%
     {
      type: "pie",
      center: ["85%", "40%"],
      clockWise: true, //顺逆时针
      hoverAnimation: false, //鼠标悬停跳动
      radius: radius,
      x: "40%", // for funnel
      itemStyle: labelFromatter,
      data: [
        {
          name: "PSCADA",
          value:systemHealth[2].healthIndex,
          itemStyle: labelFacade,
          label: lableFont
        },
        { name: "residue", value: 100-systemHealth[2].healthIndex}
      ]
    },
  ]
};
 myChart.setOption(option);

 var myChart = echarts.init(document.getElementById("faultStatistics"));
 option = {
  title: {
    text: "CIOS系统",
    subtext: "故障统计",
    top: "center",
    left: "center",
    textStyle: {
      fontSize: 20,
      color: "#606266",
      fontWeight: "normal"
    },
    subtextStyle: {
      fontSize: 20,
      color: "#606266",
      fontWeight: "normal"
    }
  },
   grid: {
    top:'20%',
     left: '3%',
     right: '4%',
     bottom: '4%',
     containLabel: true
   },
  animationDurationUpdate: 1500,
  animationEasingUpdate: "quinticInOut",
  roam: false, //鼠标缩放及平移
  focusNodeAdjacency: false, //是否在鼠标移到节点上的时候突出显示节点以及节点的边和邻接节点
  series: [
    {
      name: "",
      type: "pie",
      startAngle: 0,
      hoverAnimation: false,
      radius: ["60%", "60%"],
      center: ["50%", "50%"],
      // data:[
      //   {value:335, name:'ATS'},
      //   {value:679, name:'PSD'},
      //   {value:1548, name:'ACS'},
      //   {value:335, name:'EMCS'},
      //   {value:679, name:'FAS'},
      //   {value:1548, name:'UPS'},
      //   {value:335, name:'EMCS2'},
      //   {value:679, name:'PCSADA'},
      //   {value:1548, name:'AFC'},
      // ],
      data: getDataItem(),
      itemStyle: {
        normal: {
          color: "#606266",
          borderWidth: 15,
          borderColor: "rgba(0,0,0,0)",
          label: {
            show: true,
            formatter: "{b}",
            // formatter:function(params){
            //   return params.name+"\n故障数："+params.oldValue+"个"
            // },
            normal: {
              textStyle: {
                fontFamily: "宋体",
                color: "#606266",
                fontSize: 20
              }
            }
          },
          labelLine: {
            show: true,
            length: 70,
            lineStyle: {
              color: "#606266"
            }
          }
        }
      }
    },
    {
      type: "graph",
      tooltip: {},
      ribbonType: true,
      layout: "circular",
      hoverAnimation: false,
      width: "60%",
      height: "60%",
      circular: {
        rotateLabel: true
      },
      symbolSize: 1,
      data: roundDatas(300),
      itemStyle: {
        normal: {
          label: {
            show: false
          },
          color: "#606266"
        },
        emphasis: {
          label: {
            show: false
          }
        }
      }
    },
    {
      type: "graph",
      tooltip: {},
      ribbonType: true,
      layout: "circular",
      width: "60%",
      height: "60%",
      circular: {
        rotateLabel: true
      },
      symbolSize: 30,
      label: {
        normal: {
          // position: "center",
          // formatter: "{b}\n故障数：{c}个",
          normal: {
            textStyle: {
              fontFamily: "宋体",
            
              fontSize: 18
            },
            color: "#ffffff",
          }
        }
      },

      edgeSymbol: ["circle"],
      edgeSymbolSize: [8, 10],
      edgeLabel: {
        normal: {
          textStyle: {
            fontSize: 18,
            fontWeight: "bold",
         
            fontFamily: "宋体"
          },
          color: "#ffffff",
        }
      },

      itemStyle: {
        color: "#ffffff",
        normal: {
          label: {
            rotate: true,
            show: false,
            textStyle: {
              color: "#ffffff",
              fontSize: 20
            }
          },
          //borderColor: '#7C9ECD',
          borderWidth: 3
        },
        emphasis: {
          label: {
            show: false
          }
        }
      },
      // data:[
      //   {value:335, name:'ATS'},
      //   {value:679, name:'PSD'},
      //   {value:1548, name:'ACS'},
      //   {value:335, name:'EMCS'},
      //   {value:679, name:'FAS'},
      //   {value:1548, name:'UPS'},
      //   {value:335, name:'EMCS2'},
      //   {value:679, name:'PCSADA'},
      //   {value:1548, name:'AFC'},
      // ],
      data:getDataItem()
    }
  ]
 }
 myChart.setOption(option);

//服务器cpu使用情况
  var myChart = echarts.init(document.getElementById("classificationStatistics"));
  option = {
    // backgroundColor: "#0D2A42",
    xAxis: {
      show: false
    },
    grid: {
      x: "40%",
      width: "45%",
      height: "80%",
      top: "2%"
    },
    yAxis: [{
      show: true,
      data: ['接口服务1','实时服务2','实时服务1','历史服务2','接口服务2','历史服务1'],
      inverse: true,
      axisLine: {
        show: false
      },
      splitLine: {
        show: false
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        textStyle: {
          fontSize: 12,
          color: "#606266"
        },
        formatter: function(value, index) {
          return [value].join("\n");
        }
      }
    },
    {
      show: false,
      inverse: true,
      data:['2'],
      axisLabel: {
        textStyle: {
          fontSize: 12,
          color: "#606266"
        }
      },
      axisLine: {
        show: false
      },
      splitLine: {
        show: false
      },
      axisTick: {
        show: false
      }
    }
  ],
  xAxis: [
    {
      show:false,
      type: "value",
      // max: 100,
      splitLine: {
        show: false
      },
      axisLine: {
        show: false
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        color: "#606266"
      }
    }],
    series: [{
      name: "条",
      type: "bar",
      yAxisIndex: 0,
      data: ['11.1','15.8','25.1','20.6','10.2','17.0'],
      barWidth: "20%",
      itemStyle: {
        normal: {
          barBorderRadius: 15,
          color: "#56D0E3"
        }
      },
      label: {
        normal: {
          show: true,
          position: 'right',
          formatter: '{c}%',
        }
      }
    },
      { 
        name: '外框',
        type: 'bar',
        yAxisIndex: 0,
        barGap: '-100%',
        data: ['100','100','100','100','100','100'],
        barWidth: '20%',
        itemStyle: {
          normal: {
            color: "none",
            borderColor: "#00c1de",
            borderWidth: 2,
            barBorderRadius: 15
          }
        },
      }, 
    ]
  }
  myChart.setOption(option);

  exports('equipmentMGT', {})
});
  
    
    